package java_util;

import java.util.Stack;

import util.LogUtil;

public class StackTest {
	private static final String TAG = "StackTest\t\t";

	public static void main(String[] argz) {
		StackTest instance = new StackTest();
		instance.test();
	}

	public void test() {
		Stack<Demo> stack = new Stack<Demo>();

		final int STACK_SIZE = 3;
		// stack.setSize(STACK_SIZE);

		if (stack.size() > STACK_SIZE)
			return;

		LogUtil.e(TAG, "stack.size():" + stack.size());
		
		for (int i = 0; i < 3; i++) {
			Demo item = new Demo();
			item.setI(i);
			stack.push(item);
			LogUtil.e(TAG, "stack.size():" + stack.size() + ",item.getI():"
					+ stack.get(i).getI());
		}
		LogUtil.e(TAG, "stack.size() after push():" + stack.size());
		for (int i = 0; i <= stack.size(); i++) {
			Demo item = stack.peek();
			LogUtil.e(TAG, "stack.size():" + stack.size() + ",item.getI():"
					+ item.getI());
		}
		LogUtil.e(TAG, "stack.size() after peek():" + stack.size());
		while(stack.size() > 0) {
			Demo item = stack.pop();
			LogUtil.e(TAG, "stack.size():" + stack.size() + ",item.getI():"
					+ item.getI());
		}
		
		LogUtil.e(TAG, "final stack.size():" + stack.size());
	}

	private static class Demo {
		private int i;

		public int getI() {
			return i;
		}

		public void setI(int i) {
			this.i = i;
		}
	}
}
